﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCWeb.Models
{
    public class TvModel
    {
        [Required]
        [DisplayName("Display")]
        public int Display { get; set; }


        [Required]
        [DisplayName("Make")]
        public int Make { get; set; }

        [Required]
        [DisplayName("Size")]
        public int Size { get; set; }

        [Required]
        [DisplayName("Resolution")]
        public int Resolution { get; set; }

        [Required]
        [DisplayName("Refresh")]
        public int Refresh { get; set; }


        [Required]
        [DisplayName("Shipping")]
        public int Shipping { get; set; }

        [Required]
        [DisplayName("ProductID")]
        public int product_id {get; set; }

        [Required]
        [DisplayName("DisplayType")]
        public string display_type {get; set; }

        [Required]
        [DisplayName("MakeType")]
        public string make_type {get; set; }
         
        [Required]
        [DisplayName("SizeType")]
        public string size_type {get; set; }

        [Required]
        [DisplayName("ResType")]
        public string res_type {get; set; }

        [Required]
        [DisplayName("RefreshType")]
        public string refresh_type {get; set; }

        [Required]
        [DisplayName("Price")]
        public double price {get; set; }


        [Required]
        [DisplayName("ShipType")]
        public string ship_type {get; set; }

    }


    public class TvModelPrtial
    {
        [Required]
        [DisplayName("Display")]
        public int Display { get; set; }


        [Required]
        [DisplayName("Make")]
        public int Make { get; set; }

        [Required]
        [DisplayName("Size")]
        public int Size { get; set; }

        [Required]
        [DisplayName("Resolution")]
        public int Resolution { get; set; }

        [Required]
        [DisplayName("Refresh")]
        public int Refresh { get; set; }


        [Required]
        [DisplayName("Shipping")]
        public int Shipping { get; set; }

        [Required]
        [DisplayName("ProductID")]
        public int product_id { get; set; }

        [Required]
        [DisplayName("DisplayType")]
        public string display_type { get; set; }

        [Required]
        [DisplayName("MakeType")]
        public string make_type { get; set; }

        [Required]
        [DisplayName("SizeType")]
        public string size_type { get; set; }

        [Required]
        [DisplayName("ResType")]
        public string res_type { get; set; }

        [Required]
        [DisplayName("RefreshType")]
        public string refresh_type { get; set; }

        [Required]
        [DisplayName("Price")]
        public double price { get; set; }


        [Required]
        [DisplayName("ShipType")]
        public string ship_type { get; set; }

        [Required]
        [DisplayName("Amount Of Selling")]
        public int num_sales { get; set; }

        [Required]
        [DisplayName("Amount Of Stock")]
        public int num_stocked { get; set; }
    }

    public static class TvClientService
    {
        //SearchItem uncomment this
        public static List<TvModel> SearchItem(int display, int make, int size)
        {
            List<TvModel> tvlist = new List<TvModel>();
            SLTv.ISLTv sltv = new SLTv.SLTvClient();
            //SLOrder.ISLOrder SLOrder = new SLOrder.SLOrderClient();

            string[] errors = new string[0];

            SLTv.Product[] product = sltv.SearchItem(display, make, size, ref errors);

            if (product != null)
            {
                foreach (SLTv.Product p in product)
                {
                    TvModel item = DTO_to_PL(p);
                    tvlist.Add(item);
                }

            }
            return tvlist;
        } 
        
        public static Dictionary<int, string> GetDisplayList()
        {
          //  List<TvModel> displayList = new List<TvModel>();
            Dictionary<int, string> displaylist = new Dictionary<int, string>();

            SLTv.ISLTv SLTv = new SLTv.SLTvClient();

            string[] errors = new string[0];

            displaylist = SLTv.GetDisplay(ref errors);

            return displaylist;
        }



        private static TvModel DTO_to_PL(SLTv.Product product)
        {
            TvModel TvModel = new Models.TvModel();

            TvModel.Display = product.display_id;
            TvModel.Make = product.make_id;
            TvModel.Size = product.size_id;
            TvModel.Resolution = product.res_id;
            TvModel.Refresh = product.refresh_id;
            TvModel.Shipping = product.shipping;
            
            TvModel.product_id = product.product_id;
            TvModel.display_type = product.display_type;
            TvModel.make_type = product.make_type;
            TvModel.size_type = product.size_type;
            TvModel.refresh_type = product.refresh_type;
            TvModel.res_type = product.res_type;
            TvModel.price = product.price;
            TvModel.ship_type = product.shipping_type;


            return TvModel;
        }

        /*for partial functions */
        public static int GetNumberOfOutOfStock() 
        {
            string[] errors = new string[0];
            SLTv.ISLTv SLTV = new SLTv.SLTvClient();
            int numofoutofstock = SLTV.numberOutOfStock(ref errors);


            return numofoutofstock;
        }
        
        
        public static List<TvModelPrtial> OutOfStockDetail()
        {
            SLTv.ISLTv SLTV = new SLTv.SLTvClient();
            List<TvModelPrtial> TOPFIVE = new List<TvModelPrtial>();
            string[] errors = new string[0];

            SLTv.Product[] product = SLTV.GetOutStockDetail(ref errors);

            foreach (SLTv.Product sigleTV in product)
            {
                TvModelPrtial tranTv = DTO_TO_PSL(sigleTV);
                TOPFIVE.Add(tranTv);
            }
            return TOPFIVE;
        
        
        }

        public static List<TvModelPrtial> GetTopFive()
        {
            
            SLTv.ISLTv SLTV = new SLTv.SLTvClient();
            List<TvModelPrtial> TOPFIVE = new List<TvModelPrtial>();
            string[] errors = new string[0];

            SLTv.Product[] product = SLTV.GetTopFive(ref errors);

            foreach(SLTv.Product sigleTV in product)
            {
                TvModelPrtial tranTv = DTO_TO_PSL(sigleTV);
                TOPFIVE.Add(tranTv);              
            }
            return TOPFIVE;

        }
      

        /* end of partial functions lol*/

     /*   private static SLOrder.Product DTO_to_SL(TvModel product)
        {
            SLOrder.Product SLOrder = new MVCWeb.SLOrder.Product();

            SLOrder.display_id = product.Display;
            SLOrder.make_id = product.Make;
            SLOrder.size_id = product.Size;
            SLOrder.res_id = product.Resolution;
            SLOrder.refresh_id = product.Refresh;
            SLOrder.shipping = product.Shipping;


            return SLOrder;
        } */

        public static SLTv.Product DTO_to_SL(TvModel product)
        {
            SLTv.Product SLProduct = new MVCWeb.SLTv.Product();

            SLProduct.display_id = product.Display;
            SLProduct.make_id = product.Make;
            SLProduct.size_id = product.Size;
            SLProduct.res_id = product.Size;
            SLProduct.refresh_id = product.Refresh;
            SLProduct.shipping = product.Shipping;

            SLProduct.product_id = product.product_id;
            SLProduct.display_type = product.display_type;
            SLProduct.make_type = product.make_type;
            SLProduct.size_type = product.size_type;
            SLProduct.refresh_type = product.refresh_type;
            SLProduct.res_type = product.res_type;
            SLProduct.price = product.price;
            SLProduct.shipping_type = product.ship_type;

            return SLProduct;

        }

        // for partial view
        public static TvModelPrtial DTO_TO_PSL(SLTv.Product product)
        {
            TvModelPrtial SLProduct = new Models.TvModelPrtial();

      
            SLProduct.product_id = product.product_id;
            SLProduct.display_type = product.display_type;
            SLProduct.make_type = product.make_type;
            SLProduct.size_type = product.size_type;
            SLProduct.refresh_type = product.refresh_type;
            SLProduct.res_type = product.res_type;
            SLProduct.price = product.price;
            SLProduct.ship_type = product.shipping_type;
            SLProduct.num_sales = product.num_sales;
            SLProduct.num_stocked = product.num_stocked;

            return SLProduct;
        
        }
    }

}